package apps.softtech.fastmarket.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import apps.softtech.fastmarket.R;
import apps.softtech.fastmarket.model.ChatLog;

public class AdapterListChat extends BaseAdapter{
	ArrayList<ChatLog> mItem_Chat_Lists = new ArrayList<ChatLog>();
	Context mContext;
	LayoutInflater inf;
	public AdapterListChat(ArrayList<ChatLog> list,Context mContext){
		this.mContext = mContext;
		mItem_Chat_Lists = list;
		inf = (LayoutInflater) this.mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		return mItem_Chat_Lists.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View vi, ViewGroup arg2) {
		ViewHolder vh = null;
		
		if(vi==null){
			vh=new ViewHolder();
			vi = inf.inflate(R.layout.item_chat_list, null);
			vh.ivUser = (ImageView)vi.findViewById(R.id.ivItemChat);
			vh.tvIdUser = (TextView)vi.findViewById(R.id.tvIdUser);
			vi.setTag(vh);//
		}else{
			vh = (ViewHolder) vi.getTag();
		}
//		vh.ivUser.setImageBitmap(mItem_Chat_Lists.get(position).getDrawable());
		vh.ivUser.setBackgroundResource(R.drawable.ic_launcher);
		vh.tvIdUser.setText(""+mItem_Chat_Lists.get(position).getFromUserId());
		return vi;
	}
	public void upDate(ArrayList<ChatLog> list){
		mItem_Chat_Lists = list;
		notifyDataSetChanged();
	}
	class ViewHolder{
		ImageView ivUser;
		TextView tvIdUser;
	}
	
}
